package com.skyline.base.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.skyline.base.dao.FootprintDao;
import com.skyline.base.model.Footprint;
import com.skyline.base.service.FootprintService;
import com.skyline.base.type.ResourceType;
import com.skyline.common.bean.Page;
import com.skyline.user.model.User;

@Service("footprintService")
public class FootprintServiceImpl implements FootprintService {
	@Autowired
	private FootprintDao footprintDao;

	@Override
	public Footprint getUserFootprintOfResource(Long viewerId, Long resourceId, ResourceType resourceType) {
		return footprintDao.queryFootprint(viewerId, resourceId, resourceType);
	}

	@Override
	public List<Footprint> listFootprintsOfResource(Long resourceId, ResourceType resourceType, Page page) {
		return footprintDao.queryFootprintsOfResource(resourceId, resourceType, page);
	}

	@Override
	public List<Footprint> listFootprintsOfResource(Long resourceId, ResourceType resourceType, Integer size) {
		return footprintDao.querySomeFootprintsOfResource(resourceId, resourceType, size);
	}

	@Override
	public void createFootprint(User viewer, Long resourceId, ResourceType resourceType) {
		if(viewer == null || viewer.getId() == 0L) {
			return;
		}
		footprintDao.insertFootprint(viewer.getId(), viewer.getNickname(), viewer.getPortrait(), viewer.getEmail(),
				resourceId, resourceType);
	}

	@Override
	public void updateFootprint(User viewer, Long resourceId, ResourceType resourceType) {
		if(viewer == null || viewer.getId() == 0L) {
			return;
		}
		footprintDao.updateFootprint(viewer.getId(), viewer.getNickname(), viewer.getPortrait(), viewer.getEmail(),
				resourceId, resourceType);
	}

}
